﻿using AuthCenter.API.Application.Command.Menu;
using AuthCenter.API.DTOs;
using AuthCenter.Domain.Menu;
using AuthCenter.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AuthCenter.API.Controllers
{
    /// <summary>
    /// 菜单控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class MenuController : ControllerBase
    {
        private readonly IMediator mediator;

        public MenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加菜单信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> CreateMenu(CreateMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 修改菜单信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpdateMenu(UpdateMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除菜单信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<int>> DelMenu([FromQuery]DelMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取菜单信息成功
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<MenuDTO>>> GetMenu([FromQuery]GetMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 显示顶级菜单名称成功
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<ParentMenuDTO>>> GetParentMenuName([FromQuery]GetParentMenuCommand request)
        {
            return mediator.Send(request);
        }
    }
}
